/* 创建store */
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'
import reducer from './reducers'
import { getTokenInfo, getLocalHistories } from '@/utils/storage'
import { ThunkAction } from 'redux-thunk'
import { SearAction } from './reducers/search'
import { LoginAction } from './reducers/login'
import { HomeAction } from './reducers/home'
import { profileAction } from './reducers/profile'
import { ArticleAction } from './reducers/article'
// 参数1：reducer
// 参数2：指定store的初始值
// 参数3：指定中间件
const store = createStore(
  reducer,
  {
    login: getTokenInfo(),
    search: {
      suggestions: [],
      results: [],
      historys: getLocalHistories(),
    },
  },
  composeWithDevTools(applyMiddleware(thunk))
)
export type RootState = ReturnType<typeof store.getState>
type RootAction =
  | SearAction
  | HomeAction
  | LoginAction
  | profileAction
  | ArticleAction
export type RootThunkAction = ThunkAction<
  Promise<void>,
  RootState,
  unknown,
  RootAction
>
export default store
